home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15507 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.princeton.edu!blume
  2. From: blume@zayin.cs.princeton.edu (Matthias Blume)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is this a memory leak?
  5. Date: 05 Apr 1996 15:34:55 GMT
  6. Organization: Princeton University
  7. Distribution: world
  8. Message-ID: <BLUME.96Apr5103455@zayin.cs.princeton.edu>
  9. References: <4jv214$gv7@insosf1.netins.net> <4k02v5$tu7@grimsel.zurich.ibm.com>
  10.     <4k2vku$s82@werple.net.au> <4k39f5$lhn@grimsel.zurich.ibm.com>
  11. NNTP-Posting-Host: zayin.cs.princeton.edu
  12. In-reply-to: wgk@zurich.ibm.com's message of 5 Apr 1996 14:07:33 GMT
  13.  
  14. In article <4k39f5$lhn@grimsel.zurich.ibm.com> wgk@zurich.ibm.com (Keith Whittingham) writes:
  15.  
  16.    In <4k2vku$s82@werple.net.au>, davidw@werple.net.au (David White) writes:
  17.    >wgk@zurich.ibm.com (Keith Whittingham) writes:
  18.  
  19.    >The use of 0 as a pointer is not the address 0x000. It is a null pointer
  20.    >as defined by the language. Implementations are not even required to use a
  21.    >bit pattern of all zeroes as a null pointer. They can use any value they
  22.    >like, as long as it will not also be used as a real address. Furthermore,
  23.    >rather than being a quirk of implementation, the language guarantees that
  24.    >deleting a null pointer will do nothing. 
  25.    >
  26.  
  27.    Er, I don't think I agree. 
  28.  
  29.    The line of code (if I remember correctly) was:
  30.  
  31.       bury = 0;
  32.  
  33.    'bury' being a pointer to some element. bury *is* a pointer and it is 
  34.    assigned the value 0. 0 is the same as 0x0000. The line of code:
  35.  
  36.       bury = NULL;
  37.  
  38.    may of course set bury to some other value.
  39.  
  40. May I suggest that you are greatly mistaken.  NULL is the same as 0,
  41. and when used in a pointer context neither of them need to correspond
  42. to the bit-pattern where all bits are zero.
  43.  
  44.    If, for some compiler, a NULL pointer was implemented as a bit pattern
  45.    of all ones then we could expect the code:
  46.  
  47.       bury = 0;
  48.       delete bury;
  49.  
  50.    to have some very strange behaviour. Whereas
  51.  
  52.       bury = NULL;
  53.       delete bury;
  54.  
  55.    would be 'safe' although undesireable.
  56.  
  57. No, both would work and both would give the same result.
  58.  
  59. --
  60. -Matthias
  61.